package com.hexseek.libretvcloud.controller;

import com.hexseek.libretvcloud.model.R;
import com.hexseek.libretvcloud.model.UserConfig;
import com.hexseek.libretvcloud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhougb9
 * @version 1.0.0
 * @description TODO 用户配置
 * @date 2025/5/14 18:04
 * @title UserController
 */
@RestController
@RequestMapping("/api/user")
public class UserController {


    @Autowired
    private UserService userService;

    // 获取用户配置
    @GetMapping("/getUserConfig")
    public R<?> getUserConfig(@CookieValue(value = "userId", required = false) String userId) {

        if (userId == null || userId.isEmpty()) {
            R.fail("用户ID缺失");
        }

        UserConfig config = userService.getUserConfig(userId);

        return R.ok(config);
    }

    // 更新用户配置
    @PostMapping("/updateUserConfig")
    public R<?> updateUserConfig(@RequestBody UserConfig config, @CookieValue(value = "userId", required = false) String userId) {

        if (userId == null || userId.isEmpty()) {
            R.fail("用户ID缺失");
        }

        UserConfig updatedConfig = userService.updateUserConfig(userId, config);

        return R.ok(updatedConfig);
    }
}